﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace dotNetTraining.C_Sharp
{
    #region cau 8 Why is the virtual keyword used in code?
    class A
    {
       public virtual void Print(){
           Console.WriteLine("Class A");
       }
    }
    class B:A{
        public override void Print()
        {
            //call method from class A
             base.Print();
            // writen new attribute
             Console.WriteLine("Class B");
        }
    }
    #endregion
    #region cau 9  Can you allow a class to be inherited, but prevent a method from being overridden in C#?
    public class C
    {
        public virtual void Print()
        {
            Console.WriteLine("Class A");
        }
        // can't inherited
        //public sealed int Count()
        //{
        //    return 1 * 2 * 3;
        //}
    }
    public class D:C
    {
        public D(){
            base.Print();
            // Error cannot be sealed because it is not an override	
            // base.Count();
    }
        
    }
    #endregion
    #region 15 Does .NET support multiple inheritance? 
    public interface Color
    {
        string id();
        string Name();
    }
    public interface Computer:Color { }

    //multiple inheritance through interfaces
    //public class Dell : Color, Computer { }
    //public class HP : Computer, Color { }

    #endregion
    class Program
    {
        #region 3. What is the difference between arrays and collection?
        protected void Array_Collection()
        {
            // array
            int[] arrayInt = new int[100];

            //collection
            List<int> listInt = new List<int>();
            List<object> listObject = new List<object>();
        }

        #endregion
        #region 11. What is a data type? How many types of data types are there in .NET ?
        public void DataType()
        {
            // Value type - Refers
            int a = 3;
            int b;
            b = a;
            //Reference type
            StringBuilder val = new StringBuilder("123");
            StringBuilder val2 = new StringBuilder();
            val2 = val;
            val2.Append("456");           
            // ==> val="123456"
        }
        #endregion
        #region 13. What is a parameter? Explain the new types of parameters introduced in C# 4.0.

        public static int Sum(int a, int b, int c = 0, int d = 0)
        {
            return a + b + c + d;
        }
        public static string CreateAccount(string name, string address = "unknown", int age = 0)
        {
            return "i'm " + name +
                    " i come from " + address +
                    " i'm " + age + " years old.";
        }
        #endregion
        #region 26. What is the Difference between Ref and Out in c#
        public static void Refsample(ref int val1)
        {
            val1 += 10;
        }
        public static void Outsample(out int val1, out int val2)
        {
            val1 = 5;
            val2 = 10;
        }
        #endregion
        #region 25. String Builder and string
        public void StringDemo()
        {
            // string
            string str = "hi";
            // create a new string instance instead of changing the old one
            str += "test";
            str += "help";
            //-------------------------
           //String Builder
            StringBuilder sb = new StringBuilder("");
            sb.Append("hi");
            sb.Append("test ");
            string strBuilder = sb.ToString();
        }
        #endregion

        static void Main(string[] args)
        {
            int i, j; // No need to initialize variable
            int a = 0;// variable need to be initialized
            Refsample(ref a);
            Outsample(out i,out j);     
            #region cau 13
            Sum(1, 2);// =3
            Sum(1, 2, 3);// =6
            Sum(1, 2, 3, 4);// =10
            CreateAccount("ABC", "Viet Nam", 10);// i'm ABC i come from Viet Nam i'm 10 year old.
            CreateAccount(address: "Indonesia", name: "Fun");// i'm Fun i come from Indonesia i'm 0 year old.
            CreateAccount("ABC");// i'm ABC i come from unknown i'm 0 year old.
            //CreateAccount();// error  missing parameter name
            #endregion
            Console.ReadKey();
        }
    }
}
